package auth

import (
	"fmt"
	"encoding/json"
	"meman/libs/utils"
	"meman/sys/basic"
)

//用户权限信息
type GroupRoles struct  {
	Paths []Path
	Groups []string

}

type Path struct {
	Path string
	Name string
	Roles []string
}


func getGroupRoles(username string) (*GroupRoles, error) {
	url := fmt.Sprintf("%s%s?uid=%s&app_key=%s&app_name=%s",
		basic.Config.Auth.BaseUrl, basic.Config.Auth.GroupRolePath, username, basic.Config.Auth.AppKey, basic.Config.Auth.AppName)
	responses, err := utils.RemoteContent(url)
	if err != nil {
		return nil, fmt.Errorf("Auth: get http content err:%s", err.Error())
	}

	var groupRoles *GroupRoles
	err = json.Unmarshal(responses, &groupRoles)
	if err != nil {
		return nil, fmt.Errorf("Auth: json unmarshal user info error!err:%s", err.Error())
	}

	return groupRoles, nil
}